#include "IP.h"

IP::IP()
{}

int IP::parse(Packet* pkt)
{
	if(sizeof(IP_Header) >= pkt->pktLength - pkt->parsePos)                              
	{
		pkt->state = STATE_FAIL;                                         
		return -1;
	}

	uint8_t* data = pkt->rawPkt + pkt->parsePos;

	IP_Header* header = (IP_Header*)data;

//	printf("srcIP = %x\n", ntohl(header->srcIP));
//	printf("dstIP = %x\n", ntohl(header->dstIP));

	pkt->parsePos += (header->version_headerLength & 0x0f) * 4;

	if(6 == header->protocol)
	{
		pkt->state = STATE_TCP;
	}
	else if(47 == header->protocol)
	{
		pkt->state = STATE_GRE;
	}
	else
	{
		pkt->state = STATE_FAIL;
	}

	return 0;
}
